package m202406.d23;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/6/23 23:32
 */
public class Q746 {
    //dp[i]表示爬到i时最小花费
    //dp[i] = min(dp[i-1]+v[i-1],dp[i-2]+v[i-2])
    //结果 min(dp[n-1]+v[n-1],dp[n-2]+v[n-2])
    public int minCostClimbingStairs(int[] cost) {
        int n = cost.length;
        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = 0;
        for (int i = 2; i < n; i++) {
            dp[i] = Math.min(dp[i - 2] + cost[i - 2], dp[i - 1] + cost[i - 1]);
        }
        return Math.min(dp[n - 1] + cost[n - 1], dp[n - 2] + cost[n - 2]);
    }
}
